var xm1=null;
var xm2=null;
var xm3=null;
var xm4=null;
var xm5=null;
var xm6=null;
var citys=null;

$(function () {
    $.when(
        $.get(baseURL + 'bss/apbase/mapselect?ourid=isok&&operation=101', function (r) {
            xm1 = r.returnlist;
            $("#msgNum1").show();
            $("#msgNum1").text("("+xm1.length+")");
         }),
        $.get(baseURL + 'bss/apbase/mapselect?ourid=isok&&operation=102', function (r) {
            xm2 = r.returnlist;
            $("#msgNum2").show();
            $("#msgNum2").text("("+xm2.length+")");
        }),
        $.get(baseURL + 'bss/apbase/mapselect?ourid=isok&&operation=103', function (r) {
            xm3 = r.returnlist;
            $("#msgNum3").show();
            $("#msgNum3").text("("+xm3.length+")");
        }),
        $.get(baseURL + 'bss/apbase/mapselect?ourid=isok&&operation=104', function (r) {
            xm4 = r.returnlist;
            $("#msgNum4").show();
            $("#msgNum4").text("("+xm4.length+")");
        }),
        $.get(baseURL + 'bss/apbase/mapselect?ourid=isok&&operation=105', function (r) {
            xm5 = r.returnlist;

            $("#msgNum5").show();
            $("#msgNum5").text("("+xm5.length+")");
        }),
        $.get(baseURL + 'bss/apbase/mapselect?ourid=isok&&operation=106', function (r) {
            xm6 = r.returnlist;

            $("#msgNum6").show();
            $("#msgNum6").text("("+xm6.length+")");
        }),
       $.get(baseURL + 'sys/dept/getcity', function (r) {

           citys= r.citys;
      })

	).done(

        function () {
            if(citys==null||citys=="")
            {
                citys="遵义";
            }
            markLocation('mapContainer', citys);
        }



    )

});



function getQueryVariable(variable)
{
    var query = window.location.search.substring(1);
    var vars = query.split("&");
    for (var i=0;i<vars.length;i++) {
        var pair = vars[i].split("=");
        if(pair[0] == variable){return pair[1];}
    }
    return(false);
}



function markLocation(mapId, address) {
    AMap.plugin('AMap.Geocoder', function() {
        var geocoder = new AMap.Geocoder();
        geocoder.getLocation(address, function(status, result) {
            if (status === 'complete' && result.info === 'OK') {

                // 经纬度
                var lng = result.geocodes[0].location.lng;
                var lat = result.geocodes[0].location.lat;

                // 地图实例
                var map = new AMap.Map(mapId, {
                    resizeEnable: true,
                    expandZoomRange:true,
                    zooms:[3,20],
                    center: [lng, lat], // 设置地图的中心点
                    zoom: 10 　　　　　　 // 设置地图的缩放级别，0 - 20
                });
                AMap.plugin(['AMap.ToolBar','AMap.Scale'],function(){
                    map.addControl(new AMap.ToolBar());
                    map.addControl(new AMap.Scale());

                })



                var Group1 = new AMap.OverlayGroup();
                var Group2 = new AMap.OverlayGroup();
                var Group3 = new AMap.OverlayGroup();
                var Group4 = new AMap.OverlayGroup();
                var Group5 = new AMap.OverlayGroup();
                var Group6 = new AMap.OverlayGroup();
                for (d in  xm1) {
                    if(xm1[d].pBLongitude!=null) {
                        var marker = new AMap.Marker({
                            map: map,
                            position: [xm1[d].pBLongitude, xm1[d].pBLatitude],
                            label: {
                                content: xm1[d].pBName,
                                offset: new AMap.Pixel(20, -30)//修改label相对于maker的位置
                            }
                        })
                        Group1.add(marker);
                    }
                }
                for (d in  xm2) {
                    if(xm2[d].pBLongitude!=null) {
                        var marker = new AMap.Marker({
                            map: map,
                            position: [xm2[d].pBLongitude, xm2[d].pBLatitude],
                            label: {
                                content: xm2[d].pBName,
                                offset: new AMap.Pixel(20, -30)//修改label相对于maker的位置
                            }
                        })
                        Group2.add(marker);
                    }
                }
                for (d in  xm3) {
                    if(xm3[d].pBLongitude!=null) {
                        var marker = new AMap.Marker({
                            map: map,
                            position: [xm3[d].pBLongitude, xm3[d].pBLatitude],
                            label: {
                                content: xm3[d].pBName,
                                offset: new AMap.Pixel(20, -30)//修改label相对于maker的位置
                            }
                        })
                        Group3.add(marker);
                    }
                }
                for (d in  xm4) {
                    if(xm4[d].pBLongitude!=null) {
                        var marker = new AMap.Marker({
                            map: map,
                            position: [xm4[d].pBLongitude, xm4[d].pBLatitude],
                            label: {
                                content: xm4[d].pBName,
                                offset: new AMap.Pixel(20, -30)//修改label相对于maker的位置
                            }
                        })
                        Group4.add(marker);
                    }
                }
                for (d in  xm5) {
                    if(xm5[d].pBLongitude!=null) {
                        var marker = new AMap.Marker({
                            map: map,
                            position: [xm5[d].pBLongitude, xm5[d].pBLatitude],
                            label: {
                                content: xm5[d].pBName,
                                offset: new AMap.Pixel(20, -30)//修改label相对于maker的位置
                            }
                        })
                        Group5.add(marker);
                    }
                }
                for (d in  xm6) {
                    if(xm6[d].pBLongitude!=null) {
                        var marker = new AMap.Marker({
                            map: map,
                            position: [xm6[d].pBLongitude, xm6[d].pBLatitude],
                            label: {
                                content: xm6[d].pBName,
                                offset: new AMap.Pixel(20, -30)//修改label相对于maker的位置
                            }
                        })
                        Group6.add(marker);
                    }
                }
                map.add(Group1);
                vm.Group1 = Group1;
                map.add(Group2);
                vm.Group2 = Group2;
                map.add(Group3);
                vm.Group3 = Group3;
                map.add(Group4);
                vm.Group4 = Group4;
                map.add(Group5);
                vm.Group5 = Group5;
                map.add(Group6);
                vm.Group6 = Group6;


            } else {
                console.log('定位失败！');
            }
        });
    });
}





var vm = new Vue({
	el:'#rrapp',
	data:{
         Group1:null,
        Group2:null,
        Group3:null,
        Group4:null,
        Group5:null,
        Group6:null,
     },
	methods: {

        show1: function (event) {
            vm.Group1.show();
            vm.Group2.hide();
            vm.Group3.hide();
            vm.Group4.hide();
            vm.Group5.hide();
            vm.Group6.hide();
       },
        show2: function (event) {
            vm.Group1.hide();
            vm.Group2.show();
            vm.Group3.hide();
            vm.Group4.hide();
            vm.Group5.hide();
            vm.Group6.hide();
        },
        show3: function (event) {
            vm.Group1.hide();
            vm.Group2.hide();
            vm.Group3.show();
            vm.Group4.hide();
            vm.Group5.hide();
            vm.Group6.hide();
        },
        show4: function (event) {
            vm.Group1.hide();
            vm.Group2.hide();
            vm.Group3.hide();
            vm.Group4.show();
            vm.Group5.hide();
            vm.Group6.hide();
        },
        show5: function (event) {
            vm.Group1.hide();
            vm.Group2.hide();
            vm.Group3.hide();
            vm.Group4.hide();
            vm.Group5.show();
            vm.Group6.hide();
        },
        show6: function (event) {
            vm.Group1.hide();
            vm.Group2.hide();
            vm.Group3.hide();
            vm.Group4.hide();
            vm.Group5.hide();
            vm.Group6.show();
        }

	}
});